<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <h1>axios请求方法别名</h1>
    <button id="btnGet">get请求</button>
    <button id="btnPost">post请求</button>
    <button id="btnUpdate">put请求</button>
    <button id="btnDelete">delete请求</button>
    <script>
    // put请求和post请求类似，数据是在请求体上；get请求和delete请求类似
        const btnGet = document.querySelector('#btnGet')
        const btnPost = document.querySelector('#btnPost')
        const btnUpdate = document.querySelector('#btnUpdate')
        const btnDelete = document.querySelector('#btnDelete')

        btnGet.onclick= async function(){// axios.get(url[, config])
           try{
            const re = await axios.get('/user',{
                params:{
                    userId:'001'
                }
                
            })
            console.log(re.data)
           } catch(e){
            console.log(e.message)

           }
           
        }
        btnPost.onclick= async function(){//axios.post(url[, data[, config]])
           try{
            const re = await axios.post('/userpost',{
                name:'高高',
                age:18,
                sex:'female'
            })
            console.log(re.data)
           } catch(e){
            console.log(e.message)

           }
          
        }
        btnUpdate.onclick= async function(){//axios.put(url[, data[, config]])
           try{
            const re = await axios.put('/userUpdate',{
                name:'高高',
                age:18,
                sex:'female'
            })
            console.log(re.data)
           } catch(e){
            console.log(e.message)

           }
          
        }
        btnDelete.onclick= async function(){//axios.delete(url[, config])
           try{
            const re = await axios.delete('/userDelete',{
                params:{
                    userId:'001'
                }
                
            })
            console.log(re.data)
           } catch(e){
            console.log(e.message)

           }
           
        }

    </script>

</body>
</html>